/*
 *  Copyright (c) 2015 The CCP project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
 *  that can be found in the LICENSE file in the root of the web site.
 *
 *   http://www.yuntongxun.com
 *
 *  An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */package com.kaichaohulian.baocms.ecdemo.photopicker.utils;

import android.content.Context;
import android.net.Uri;
import android.provider.MediaStore.Images.Media;
import android.support.v4.content.CursorLoader;
import static android.provider.MediaStore.MediaColumns.MIME_TYPE;

/**
 * 图片加载工具类
 * @author 容联•云通讯
 * @since 2016-4-6
 * @version 5.0
 */
public class PhotoDirectoryLoader extends CursorLoader {

	  final String[] IMAGE_PROJECTION = {
	      Media._ID,
	      Media.DATA,
	      Media.BUCKET_ID,
	      Media.BUCKET_DISPLAY_NAME,
	      Media.DATE_ADDED
	  };

	  public PhotoDirectoryLoader(Context context, boolean showGif) {
	    super(context);

	    setProjection(IMAGE_PROJECTION);
	    setUri(Media.EXTERNAL_CONTENT_URI);
	    setSortOrder(Media.DATE_ADDED + " DESC");

	    setSelection(
	        MIME_TYPE + "=? or " + MIME_TYPE + "=? " + (showGif ? ("or " + MIME_TYPE + "=?") : ""));
	    String[] selectionArgs;
	    if (showGif) {
	      selectionArgs = new String[] { "image/jpeg", "image/png", "image/gif" };
	    } else {
	      selectionArgs = new String[] { "image/jpeg", "image/png" };
	    }
	    setSelectionArgs(selectionArgs);
	  }


	  private PhotoDirectoryLoader(Context context, Uri uri, String[] projection, String selection,
	      String[] selectionArgs, String sortOrder) {
	    super(context, uri, projection, selection, selectionArgs, sortOrder);
	  }
}